#include <iostream>
#include <vector>

using namespace std;

vector<int> intersection(vector<int>& nums1, vector<int>& nums2) {
    int flg[1000] {};
    vector<int> result {};
    for (int i = 0, len = nums1.size(); i < len; i++) {
        if(!flg[nums1[i]]) {
            flg[nums1[i]] = 1;
        }
    }
    for (int i = 0, len = nums2.size(); i < len; i++) {
        if (flg[nums2[i]]) {
            result.push_back(nums2[i]);
            flg[nums2[i]] = 0;
        }
    }

    return result;
}

void printVector(vector<int>& nums) {
    for (int i = 0, len = nums.size(); i < len; i++) {
        cout << "nums" << "[ " << i << " ] = " << nums[i] << "\n";
    }
}

int main() {
    vector<int> nums1 { 4, 9, 5 };
    vector<int> nums2 { 9, 4, 9, 8, 4 };

    vector<int> result = intersection(nums1, nums2);

    printVector(result);

    return 0;
}